﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class AquacultureDetail : YuanlinUserControl,
        IReplyConverter<AquacultureReply, GetOperation>
    {
        protected Repeater list;
        protected Repeater section1List;
        protected Repeater section2List;
        protected Repeater section3List;
        protected Repeater section4List;
        protected Repeater section5List;
        protected Repeater section6List;
        protected Repeater section7List;
        private Aquaculture aquaculture;
        private int entityId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.AquacultureId);
        public int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetAquacultureRequest(this));
        }

        public void BindData()
        {
            ArrayList aquacultureList = new ArrayList();

            if (aquaculture != null)
            {
                aquacultureList.Add(aquaculture);
            }

            this.list.DataSource = aquacultureList;
            this.list.DataBind();

            BindData(section1List, 1);
            BindData(section2List, 2);
            BindData(section3List, 3);
            BindData(section4List, 4);
            BindData(section5List, 5);
            BindData(section6List, 6);
            BindData(section7List, 7);
        }
        private void BindData(Repeater sectionList, int categoryId)
        {
            AquacultureSection_SectionListRequest request = new AquacultureSection_SectionListRequest();
            request.AquacultureId = entityId;
            request.CategoryType = categoryType;
            request.CategoryId = categoryId;
            request.Enabled = 1;
            request.PageSize = int.MaxValue;
            sectionList.DataSource = BusinessManager.GetAquacultureSection_SectionList(RequestHelper.BuildGetAquacultureSection_SectionListRequest(request));
            sectionList.DataBind();

        }

        #region IReplyConverter<AquacultureReply,GetOperation> Members

        public void ConvertReply(AquacultureReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                aquaculture = reply.Entity as Aquaculture;

                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
